﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
using System.Windows.Media.Imaging;
using System.ComponentModel;

namespace WGM_Silverlight.Classes
{
    public static class HelperFunctions
    {

        public static Color GetContactColour(WGM_Svc.UserOptions uo)
        {
            return Color.FromArgb(255,(byte)uo.FontColourR, (byte)uo.FontColourG, (byte)uo.FontColourB);

        }
        public static FontWeight GetFontWeight(WGM_Svc.UserOptions uo)
        {
            if (uo.IsFontBold == true)
                return FontWeights.Bold;
            else
                return FontWeights.Normal;
        }
        public static FontStyle GetFontStyle(WGM_Svc.UserOptions uo)
        {
            if (uo.IsFontItalics == true)
                return FontStyles.Italic;
            else
                return FontStyles.Normal;
        }
        public static string GetIntroString(WGM_Svc.UserOptions clientData)
        {

            string retVal = clientData.DisplayName;
            if (clientData.DisplayName.Trim() == "")
                retVal = clientData.UserName;

            
            return retVal;
        }
        public static string GetContactTitle(WGM_Svc.UserOptions clientData)
        {
            string retVal = clientData.DisplayName;
            if (clientData.DisplayName.Trim() == "")
                retVal = clientData.UserName;
            if (clientData.UserStatus != null && clientData.UserStatus.Trim() != "")
                retVal += " - " + clientData.UserStatus;

            return retVal;
        }

        public static string GetCLToolTip(WGM_Svc.UserOptions clientData)
        {
            string retVal = clientData.DisplayName;
            if (clientData.UserStatus != null && clientData.UserStatus.Trim() != "")
                retVal += " - " + clientData.UserStatus;

            retVal += " (" + clientData.UserName + ")";

            return retVal;
        }
        public static bool IsMessageValid(WGM_Svc.WGMMessage message, DateTime logonTime)
        {
            if (message.TimeStamp < logonTime)
                return false;


            return true;
        }
        public static ImageSource ByteArrayToImage(byte[] byteArrayIn)
        {
            MemoryStream ms = new MemoryStream(byteArrayIn);
            BitmapImage returnImage = new BitmapImage();
            ms.Seek(0, SeekOrigin.Begin);
            
            
            returnImage.SetSource(ms);
            return returnImage;
        } 
        public static bool AreStringsEqual(string strA, string strB, bool ignoreCase)
        {
            if (String.Compare(strA.Trim(), strB.Trim(),ignoreCase==true? StringComparison.OrdinalIgnoreCase:StringComparison.Ordinal) == 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
